package com.mycompany.biblio.controller;

import com.mycompany.biblio.business.FriendDAO;
import com.mycompany.biblio.business.SecurityService;
import com.mycompany.biblio.model.FriendRequest;

import com.mycompany.biblio.model.Status;
import com.mycompany.biblio.model.User;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.ListDataModel;

import java.util.Date;
import java.util.List;

@ManagedBean
@SessionScoped
public class FriendController
{

    // ======================================
    // =             Attributes             =
    // ======================================

    @EJB
    private FriendDAO friendEJB;
    
    @EJB
    private SecurityService securityService;
    
    private FriendRequest friend = new FriendRequest();
    private ListDataModel friendList;


    // ======================================
    // =           Public Methods           =
    // ======================================

    public void doNew() 
    {
        friend = new FriendRequest();        
    }

    public String doCreate()
    {       
        try
        {            
            friend.setDateinvitation(new Date());
            friend = friendEJB.create(friend);            
        }
        catch (Exception ex)
        {              
            return null;
        }
        doNew();
        return "/private/actualites.xhtml";
    }
    
    public String doSave() {
        friend = friendEJB.update(friend);
        return "listFriends.xhtml?faces-redirect=true";
    }
    // ======================================
    // =          Getters & Setters         =
    // ======================================

    public FriendRequest getFriendRequest() {
        return friend;
    }

    public void setFriendRequest(FriendRequest friend) {
        this.friend = friend;
    }

    
}